//在职信息 显示表格及js实体

Ext.define('InServiceInfo', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
		, "EmpId"   //员工Id
		, "EmpName"   //员工姓名	
		, "CustomerName"   //所在公司
        , "Department"  //所在部门
		, "EntryDate"   //入职日期
		, "QuitDate"   //离职日期
		, "WorkingState"   //工作状态
		, "Duties"   //职务
		, "Position"   //职位
		, "BusinessPhone"   //办公电话
		, "PhoneNumber"   //联系电话
		, "BusinessEmail"   //办公邮件
		, "ReportTo"   //汇报对象
    ],
    idProperty: "Id"
});

Ext.define('SHApp.EmployeeInfo.InServiceInfo.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.employeebill.grid',
    requires: ['SHApp.EmployeeInfo.InServiceInfo.Form'],
    txtEmpNameID: 'txtEmpName',
    txtCustomerNameID: 'txtCustomerName',
    dataModel: "InServiceInfo",
    firstLoad: true,
    dataUrl: "api/inserviceinfo?format=json",
    empId: "",
    empName: "",
    customerId: "",
    customerName: "",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.txtEmpNameID += me.id;
        me.txtCustomerNameID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [{
            text: "Id",
            flex: 1,
            dataIndex: 'Id',
            sortable: false,
            hidden: true
        }, {
            text: "员工Id",
            width: 100,
            dataIndex: 'EmpId',
            sortable: true,
            hidden: true
        }, {
            text: "员工姓名",
            width: 100,
            dataIndex: 'EmpName',
            sortable: true
        }, {
            text: "所在公司",
            width: 100,
            dataIndex: 'CustomerName',
            sortable: true
        }, {
            text: "所在部门",
            width: 100,
            dataIndex: 'Department',
            sortable: true
        }, {
            text: "入职日期",
            width: 100,
            dataIndex: 'EntryDate',
            sortable: true,
            renderer: formatDate
        }, {
            text: "离职日期",
            width: 100,
            dataIndex: 'QuitDate',
            sortable: true,
            renderer: formatDate
        }, {
            text: "工作状态",
            width: 100,
            dataIndex: 'WorkingState',
            sortable: true
        }, {
            text: "职务",
            width: 100,
            dataIndex: 'Duties',
            sortable: true
        }, {
            text: "职位",
            width: 100,
            dataIndex: 'Position',
            sortable: true
        }, {
            text: "汇报对象",
            width: 100,
            dataIndex: 'ReportTo',
            sortable: true
        }, {
            text: "办公电话",
            width: 100,
            dataIndex: 'BusinessPhone',
            sortable: true
        }, {
            text: "联系电话",
            width: 100,
            dataIndex: 'PhoneNumber',
            sortable: true
        }, {
            text: "办公邮件",
            width: 100,
            dataIndex: 'BusinessEmail',
            sortable: true
        }
		]
    },
    creatTbar: function () {
        var me = this;


        me.tbar = [

        /*
        {
        xtype: 'textfield',
        disabled: false,
        fieldLabel: '员工姓名:',
        labelWidth: 60,
        name: 'EmpName',
        id: me.txtEmpNameID,
        width: 180
        }, {
        xtype: 'textfield',
        disabled: false,
        fieldLabel: '所在公司:',
        labelWidth: 60,
        name: 'CustomerName',
        id: me.txtCustomerNameID,
        width: 180
        }, ' ', {
        xtype: 'button',
        text: '查询',
        iconCls: 'icon-btn-search',
        handler: function () {
        me.clearFilters();
        me.addFilter("EmpId", me.empId);
        var vEmpName = me.down("#" + me.txtEmpNameID).getValue();
        if (vEmpName && vEmpName.length > 0) {
        me.addFilter("EmpName", vEmpName);
        }
        var vCustomerName = me.down("#" + me.txtCustomerNameID).getValue();
        if (vCustomerName && vCustomerName.length > 0) {
        me.addFilter("CustomerName", vCustomerName);
        }
        me.loadByFilter();
        }
        },

        */

         '->', {
             xtype: 'button',
             text: '添加',
             id: me.btnAddID,
             iconCls: 'icon-btn-add',
             handler: function () {
                 var win = me.getForm('SHApp.EmployeeInfo.InServiceInfo.Form');
                 win.loadRecord(new InServiceInfo({ Id: null, EmpId: me.empId, EmpName: me.empName, CustomerId: me.customerId, CustomerName: me.customerName }));
                 win.Show("添加");
             }
         }, ' ', {
             xtype: 'button',
             disabled: true,
             id: me.btnEditID,
             text: '修改',
             iconCls: 'icon-btn-edit',
             handler: function () {
                 var rs = me.getSelectionModel().getSelection();
                 if (rs) {
                     if (rs.length > 0) {
                         rs[0].data.EntryDate = formatDate(rs[0].data.EntryDate);
                         rs[0].data.QuitDate = formatDate(rs[0].data.QuitDate);
                         me.EditData(me.getForm('SHApp.EmployeeInfo.InServiceInfo.Form'));
                     }
                 }
             }
         }, ' ', {
             xtype: 'button',
             disabled: true,
             id: me.btnDeleteID,
             text: '删除',
             iconCls: 'icon-btn-delete',
             handler: function () {
                 me.DeleteData();
             }
         }
        ]
    }
})

